var path = require('path');
var Express = require('express');
var http = require('http');
var proxy = require('http-proxy-middleware');

const app = new Express();
const port = 8989;

app.use(Express.static(path.join(process.cwd(), '/')));

app.use('/api', proxy({
				target: 'https://ms.yunlian.in:9002',
        changeOrigin: true,
        pathRewrite: {
          '^/api': ''
        },
        secure: false
      }));

app.get('/index.html', function (req, res) {
  res.sendfile('index.html');
});


const server = http.Server(app);

server.listen(port,(error) => {
  if (error) {
    console.error(error)
  } else {
    console.info(`==> 🌎  Listening on port ${port}. Open up http://localhost:${port}/ in your browser.`)
  }
});
